package com.kun.order.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.kun.order.vo.CountPayTypeVo;
import com.kun.order.vo.MonthSaleByYearVo;
import com.kun.order.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.kun.order.entity.OrderEntity;
import com.kun.order.service.OrderService;
import com.kun.common.utils.PageUtils;
import com.kun.common.utils.R;


/**
 * 
 *
 * @author kun_er
 * @email 2661038743@qq.com
 * @date 2022-05-02 16:08:08
 */
@RestController
@RequestMapping("order/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 统计支付方式的人数
     */
    @GetMapping("/getCountPayType")
    public R getCountPayType(){
        List<CountPayTypeVo> vo= orderService.getCountPayType();
        return R.ok().put("data",vo);
    }
    /**
     * 统计每年的每月销售额；
     */
    @GetMapping("/getMonthSaleByYear")
    public  R getMonthSaleByYear(@RequestParam("year") String year){
        List<MonthSaleByYearVo> vo= orderService.getMonthSaleByYear(year);
        return R.ok().put("data",vo);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
		OrderVo orderVo = orderService.getOrderDestailedById(id);

        return R.ok().put("order", orderVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderEntity orderEntity){
		orderService.save(orderEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateOrderVoById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @GetMapping("/delete")
    public R delete(@RequestParam String id){
		orderService.removeOrderVoById(id);

        return R.ok();
    }

}
